package com.info.zhiduoduo.repository.mapper.invoice;

import com.baomidou.mybatisplus.mapper.BaseMapper;
import com.info.zhiduoduo.repository.dto.invoice.CompanyInventoryRecordDto;
import com.info.zhiduoduo.repository.dto.invoice.InvoiceInventoryRecordDto;
import com.info.zhiduoduo.repository.entity.invoice.CompanyInventoryRecord;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.Date;
import java.util.List;

public interface CompanyInventoryRecordMapper extends BaseMapper<CompanyInventoryRecord>{



    // 获取 主体企业的 发票出入库 记录列表
    @Select(" SELECT cir.* , cp.company_name as companyName, " +
            " inv.projectname,inv.compname,inv.managerid " +
            " FROM zdd_invoice_company_inventory_record cir " +
            " LEFT JOIN zdd_crowdsource_company_party cp on cp.id = cir.company_id " +
            " left join zdd_invoice inv on cir.invoice_id=inv.id " +
            " WHERE " +
            "  IF( ISNULL(#{name}) or #{name} = '' , 1 = 1  , cp.company_name like '%${name}%'  )  " +
            " and DATE(cir.createtime) between #{startDate} and #{endDate} " +
            " and deleted = 0 " +
            " order by id desc ")
    List<CompanyInventoryRecordDto> findCompanyInventoryRecordList(@Param("name") String name, @Param("startDate") Date startDate, @Param("endDate") Date endDate);


@Select(" select sum(if(state=2,invoice_num,-invoice_num)) from " +
        " zdd_invoice_company_inventory_record " +
        " where deleted=0 and state!=1 and company_id=#{companyId} and " +
        " invoice_type=#{invoiceType} and amount_type=#{amountType} ")
     Integer getInvoiceSum(@Param("companyId")Integer companyId,@Param("amountType")Integer amountType,@Param("invoiceType")Integer invoiceType);


}
